//
//  RCAttendPersonsListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-29.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCAttendPersonsListDataModel.h"
#import "KFObjectExtension.h"


@implementation RCAttendPersonItemDataModel

@synthesize attendID = _attendID;
@synthesize title    = _title;
@synthesize dateTime = _dateTime;
@synthesize phone = _phone;


- (void) dealloc
{
    KF_RELEASE_SAFELY(_attendID);
    KF_RELEASE_SAFELY(_dateTime);
    KF_RELEASE_SAFELY(_phone);
    KF_RELEASE_SAFELY(_title);
    [super dealloc];
}
@end

@implementation RCAttendPersonsListDataModel


// 将JSON数据解析为数据模型
+(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    RCAttendPersonsListDataModel *retObject = [[[RCAttendPersonsListDataModel alloc] init] autorelease];
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCAttendPersonItemDataModel *item = [[RCAttendPersonItemDataModel alloc] init];
        item.attendID = [dic stringValueForKey:@"dataid" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.dateTime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.title = [dic stringValueForKey:@"name" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.phone = [dic stringValueForKey:@"phone" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    return retObject;
}
@end
